package com.audio.mapper;

import com.audio.pojo.entity.Log;
import com.audio.pojo.entity.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {


    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    @Select("select id_role from user where id = #{currentUserId}")
    int getId_Role(Long currentUserId);

    @Update("update user set id_role = id_role - 1 where id = #{currentUserId}")
    void updateUserRole(Long currentUserId);

    @Select("select * from user where id = #{id}")
    User getById(Long id);


    @Select("select * from log where user_id = #{userId} order by creat_time desc")
    List<Log> getLog(Long userId);

    @Insert("INSERT INTO log (audio_name, algorithm, parameter, result, user_id, username, user_phone, creat_time, comment, audio_path)" +
            " VALUES (#{audioName}, #{algorithm}, #{parameter}, #{result}, #{userId}, #{username}, #{userPhone}, #{creatTime}, #{comment}, #{audioPath})")
    void saveLog(Log log);
}
